import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;

class P615 {

	private static Scanner scanner;

	public static void main(String[] args) {
		scanner = new Scanner();
		int x = scanner.getInt();
		int y = scanner.getInt();
		
		int cases = 1;
		
		while (x >= 0 && y >= 0) {
			process(x, y, cases);
			cases++;
			x = scanner.getInt();
			y = scanner.getInt();
		}
	}

	private static void process(int x, int y, int cases) {
		Hashtable graph = new Hashtable();
		boolean isTree = true;
		int numberOfNodes = 0;
		int numberOfNodesPointedTo = 0;
		
		while (x > 0 && y > 0) {
			Node nodeX = new Node(x);
			Node nodeY = new Node(y);
			
			Node auxX = (Node) graph.get(nodeX);
			
			if (auxX == null) {
				numberOfNodes++;
				graph.put(nodeX, nodeX);
				auxX = nodeX;
			}
			
			Node auxY = (Node) graph.get(nodeY);
						
			if (auxY == null) {
				numberOfNodes++;
				graph.put(nodeY, nodeY);
				auxY = nodeY;
			}
			
			auxX.addNodio(auxY);
			if (!auxY.pointed) {
				numberOfNodesPointedTo++;
				auxY.pointed = true;
			} else {
				isTree = false;
			}
			
			x = scanner.getInt();
			y = scanner.getInt();
		}		
		
		if (graph.isEmpty()) {
			System.out.println("Case " + cases + " is a tree.");
			return;
		}
		
		if (!isTree) {
//			System.out.println("more than one pointed");
			System.out.println("Case " + cases + " is not a tree.");
			return;
		}
		
		if (numberOfNodes - numberOfNodesPointedTo != 1) {
//			System.out.println("more than one root");
			System.out.println("Case " + cases + " is not a tree.");
			return;
		}
	
		Node root = getRoot(graph);

		root.visited = true;
				
		Vector toVisit = new Vector();
		
		int lengthToVisit = root.adj.size();
		
		for (int k = 0; k < lengthToVisit; k++) {
			toVisit.addElement(root.adj.elementAt(k));
		}
		
		
		while (!toVisit.isEmpty()) {
			Node visitedNode = (Node) toVisit.elementAt(0);
			toVisit.removeElement(visitedNode);
			visitedNode.visited = true;
			int length = visitedNode.adj.size();
			for (int k = 0; k < length; k++) {
				Node toVisitNode = (Node) visitedNode.adj.elementAt(k);
				if (toVisitNode.visited) {
//					System.out.println("cycles");
					System.out.println("Case " + cases + " is not a tree.");
					return;
				} else {
					toVisit.addElement(toVisitNode);
				}
			}
		}
		
		if (!allVisited(graph)) {
//			System.out.println("disconnected");
			System.out.println("Case " + cases + " is not a tree.");
			return;
		}
		
		System.out.println("Case " + cases + " is a tree.");
	}

	private static boolean allVisited(Hashtable graph) {
		Enumeration nodesIt = graph.elements();
		while (nodesIt.hasMoreElements()) {
			Node node = (Node) nodesIt.nextElement();
			if (!node.visited) {
				return false;
			}
		}
		return true;
	}

	private static Node getRoot(Hashtable graph) {
		Enumeration nodes = graph.elements();
		while (nodes.hasMoreElements()) {
			Node node = (Node)nodes.nextElement();
			if (!node.pointed) {
				return node;
			}
		}
		return null;
	}
	
}

class Scanner {

    StringTokenizer st = null;

    int getInt() {
            if(st == null) st = new StringTokenizer(Reader.readLn());
            while(! st.hasMoreTokens()) st = new StringTokenizer(Reader.readLn());
            return Integer.parseInt(st.nextToken());
    }

}

class Reader {
static String readLn() {
    String newLine = System.getProperty("line.separator");
    StringBuffer buffer = new StringBuffer();
    int car = -1;
    try {
        car = System.in.read();
        while ((car > 0) && (car != newLine.charAt(0))) {
            buffer.append((char)car);
            car = System.in.read();
        }
        if (car == newLine.charAt(0))
        System.in.skip(newLine.length() - 1);
    } catch (java.io.IOException e) { return (null);}
    if ((car < 0) && (buffer.length() == 0)) return (null);
    return (buffer.toString()).trim();
}
}

class Node {

	   int id;

	   Vector adj;

	   boolean pointed;
	   
	   boolean visited;
	   
	   public Node(int id) {
	       this.id = id;
	       this.adj = new Vector();
	       pointed = false;
	   }

	   public void addNodio(Node otherNodio) {
	           adj.addElement(otherNodio);
	   }

	   public int hashCode() {
		   return id;
	   }
	   
	   public boolean equals(Object o) {
	       Node otherNodio = (Node) o;
	       return otherNodio.id == this.id;
	   }
	   
	   public String toString() {
		   return "[ID:\t" + id + ",p="+pointed+" ]";
	   }
	   
	}